package img;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author wzby
 * @Date: 2022/8/3 15:48
 */
public class Img4 {
    public static void main(String[] args) {

        var w = 600;
        var h = 600;
        var img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = img.createGraphics();

        g.setColor(Color.BLACK);
        g.fillRect(0, 0, w, h);
        g.setColor(new Color(255, 0, 0, 100));
        g.fillOval(100, 100, 400, 400);
        g.setColor(new Color(0, 255, 0, 100));
        g.fillOval(100, 150, 300, 300);
        g.setColor(new Color(0, 0, 255, 100));
        g.fillOval(150, 100, 400, 400);
        //new Color（0xff，0xff，0，0）第四个参数为透明度，0完全透明，255不透明

        //字体对象
        g.setColor(Color.YELLOW);
        Font f = new Font("宋体",Font.BOLD,100);
        f = f.deriveFont(Font.PLAIN,100);
        g.setFont(f);
        g.drawString("王珂王珂",50,350);

        g.dispose();
        try {
            ImageIO.write(img, "png", new File("ch09/src/pho/img4.png"));
            Runtime.getRuntime().exec("cmd /k start ch09/src/pho/img4.png");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
